package com.adnaan.backend.controller.admin;

import com.adnaan.backend.common.model.Result;
import com.adnaan.backend.service.DashboardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.Map;

@RestController
@RequestMapping("/dashboard")
@Tag(name = "仪表盘", description = "仪表盘数据统计")
public class DashboardController {

    @Resource
    private DashboardService dashboardService;

    @GetMapping("/statistics")
    @Operation(summary = "获取统计数据")
    public Result<Map<String, Object>> getStatistics() {
        return Result.success(dashboardService.getStatistics());
    }

    @GetMapping("/order/trend")
    @Operation(summary = "获取订单趋势")
    public Result<Map<String, Object>> getOrderTrend(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        return Result.success(dashboardService.getOrderTrend(startDate, endDate));
    }

    @GetMapping("/user/activity")
    @Operation(summary = "获取用户活跃度")
    public Result<Map<String, Object>> getUserActivity(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        return Result.success(dashboardService.getUserActivity(startDate, endDate));
    }

    @GetMapping("/recognize/stats")
    @Operation(summary = "获取识别记录统计")
    public Result<Map<String, Object>> getRecognizeStats() {
        return Result.success(dashboardService.getRecognizeStats());
    }

    @GetMapping("/article/stats")
    @Operation(summary = "获取文章统计数据")
    public Result<Map<String, Object>> getArticleStats(@RequestParam String timeRange) {
        return Result.success(dashboardService.getArticleStats(timeRange));
    }
} 